//***************************************************************************
//*
//*	File:			DialogProgress.h
//*	Description:	Dialog for displaying build progress
//*
//***************************************************************************
//*
//*	Note:			This source code is provided "as is" meaning that you may 
//*					use it at your own risk. 
//*					You are free to use it in any way you like.
//*
//***************************************************************************
//*
//*	History:		
//*
//*	-------------------------------------------------------------------------
//*	2003/07/27	|	Initial release									|	rk
//*	-------------------------------------------------------------------------
//*
//***************************************************************************

//
//-------------------------------------------------------------- PREPROCESSOR 
//

#ifndef			__DIALOGPROGRESS_H_INCLUDED
#define			__DIALOGPROGRESS_H_INCLUDED

#if				_MSC_VER > 1000
#pragma once
#ifdef			__SWITCH_SHOW_HEADER
#pragma message ("-- DialogProgress.h\n")
#endif
#ifdef			__SWITCH_SHOW_HEADER_TREE
#pragma message ("-- "__FILE__"\n")
#endif
#endif 

//
//-------------------------------------------------------------- DEPENDENCIES
//

//
//--------------------------------------------------------- CLASS DECLARATION
//

//***************************************************************************
//**	@DOC		CLASS CDialogProgress
//***************************************************************************
//*		@CLASS		Dialog for displaying build progress
//**	@BASE		Dialog
//***************************************************************************
class CDialogProgress : public CDialog
{
	DECLARE_EASYSIZE

	//																									
	//-----------------------------------------------------------------------							
	//***************************     CLASSES     ***************************
	//-----------------------------------------------------------------------							
	//																									
private:																					// @ACCESS			Private Classes
	class CProject																			// @CMEMBER,MCLASS	A project
	{																						// 
	public:																					// @@ACCESS			Public Attributes
		CComPtr< IConfiguration >	m_pIConfiguration	;									// @@CMEMBER		Pointer to the project's configuration interface
	public:																					// @@ACCESS			Public Attributes
		CString						m_strProjectName	;									// @@CMEMBER		Project's name
		CString						m_strProjectPath	;									// @@CMEMBER		Project's path
		CString						m_strWorkspaceName	;									// @@CMEMBER		Project's workspace's name
		CString						m_strWorkspacePath	;									// @@CMEMBER		Project's workspace's path
		CArray< CString, CString& > m_arrConfigurations	;									// @@CMEMBER		Project's configurations
		INT							m_bEnabled		: 1	;									// @@CMEMBER		Flag indicating whether project is enabled
		INT											: 0	;									// @@CMEMBER		Reserved flags

	private:																				
		void CopyFrom( const CProject& a_prjOther )											
		{
			this->m_pIConfiguration		= a_prjOther.m_pIConfiguration	;
			this->m_strProjectName		= a_prjOther.m_strProjectName	;
			this->m_strProjectPath		= a_prjOther.m_strProjectPath	;
			this->m_strWorkspaceName	= a_prjOther.m_strWorkspaceName	;
			this->m_strWorkspacePath	= a_prjOther.m_strWorkspacePath	;
			this->m_bEnabled			= a_prjOther.m_bEnabled			;

			this->m_arrConfigurations.RemoveAll();

			for ( int iConfiguration = 0; iConfiguration < a_prjOther.m_arrConfigurations.GetSize(); iConfiguration++ )
			{
				CString strCopy = a_prjOther.m_arrConfigurations[ iConfiguration ];			// just for C4239's sake
				this->m_arrConfigurations.Add( strCopy );
			}
		}

	public:
		CProject& operator = ( const CProject& a_prjOther ) { this->CopyFrom( a_prjOther ); return (*this); }
		CProject( const CProject& a_prjOther )				{ (*this) = a_prjOther; }
		CProject()											{ /*no init*/ }
	};

	//																									
	//-----------------------------------------------------------------------							
	//****************************     ENUMS     ****************************
	//-----------------------------------------------------------------------							
	//																									
private:																					// @ACCESS			Private Enumerations
	enum EBuildMode																			// @CMEMBER,MENUM	Build modes
	{																						// 
		EBuildMode_Clean																	// @@EMEM			Clean configurations
	,	EBuildMode_Build																	// @@EMEM			Build configurations
	,	EBuildMode_Rebuild																	// @@EMEM			Rebuild configurations
	};																						

	//																									
	//-----------------------------------------------------------------------							
	//***************************     ATTRIBS     ***************************							
	//-----------------------------------------------------------------------							
	//																									
private:																					// @ACCESS	Private Attributes	
	//{{AFX_DATA(CDialogProgress)
	enum { IDD = IDD_PROGRESS };
	CProgressCtrl					m_ctrlProgress		;									// @CMEMBER	Progress control
	CButton							m_ctrlButtonPause	;									// @CMEMBER	Pause/Resume button
	CListCtrl						m_ctrlListProgress	;									// @CMEMBER Progress list control
	//}}AFX_DATA

	CArray< CProject, CProject& >	m_arrProjects		;									// @CMEMBER	Array of projects
	CArray< CProject, CProject& >	m_arrPending		;									// @CMEMBER Array of pending projects (build launched and waiting for finish event)
	CString							m_strActiveWorkspace;									// @CMEMBER Path to the latest opened workspace
	BOOL							m_bCancelled		;									// @CMEMBER	Flag indicating whether building has been paused
	BOOL							m_bPaused			;									// @CMEMBER Flag indicating whether building has been cancelled
	EBuildMode						m_enuMode			;									// @CMEMBER	Current build mode
	IApplication*					m_pIApplication		;									// @CMEMBER Pointer to application's interface
																							
	CString							m_strSendTo			;									// @CMEMBER SendTo address	for e-mail notifications
	CString							m_strStatusLine		;									// @CMEMBER	Status line		for e-mail notifications
	CString							m_strFileToSend		;									// @CMEMBER Message body	for e-mail notifications
	BOOL							m_bSendFile			;									// @CMEMBER Flag indicating whether to send file as mail body
	BOOL							m_bIncBuildResults	;									// @CMEMBER Flag indicating whether to include results in mail subject
	BOOL							m_bMailOnEach		;									// @CMEMBER Flag indicating whether to send a mail on each project
	BOOL							m_bSendMail			;									// @CMEMBER Flag indicating whether to send mail

	long							m_lTotalErrors		;									// @CMEMBER	Total number of errors
	long							m_lTotalWarnings	;									// @CMEMBER	Total number of warnings

public:																						// @ACCESS	Public Attributes	
	INT								m_iFinishedAction	;									// @CMEMBER	Action to take when all builds have been finished

	//																							
	//-----------------------------------------------------------------------					
	//***************************     GET/SET     ***************************					
	//-----------------------------------------------------------------------					
	//																							
public:																						// @ACCESS	Public Get/Set Methods	
	void SetApplication	( IApplication*			a_pIApplication		)			;			// @CMEMBER	Sets the pointer to the application's interface

	//																							
	//-----------------------------------------------------------------------					
	//*************************     PERISTENCE     **************************					
	//-----------------------------------------------------------------------					
	//																							
private:																					// @ACCESS	Private Persistency Methods	
	void LoadProfile	( void )												;			// @CMEMBER	Loads profile settings from the registry

	//																							
	//-----------------------------------------------------------------------					
	//**************************     EXECUTION     **************************
	//-----------------------------------------------------------------------					
	//																							
private:																					// @ACCESS	Private Execution Methods	
	BOOL Execute		( const CProject&		a_Project
						,		INT				a_iConfiguration	)			;			// @CMEMBER	Executes the specified configuration of the specified project
	BOOL Execute		( const CProject&		a_Project
						,		IConfiguration*	a_pIConfiguration	)			;			// @CMEMBER	Executes the specified configuration of the specified project
	BOOL Execute		( const CString&		a_strConfiguration	)			;			// @CMEMBER	Executes the specified configuration
public:																						// @ACCESS	Public Execution Methods	
	BOOL Execute		( const CString&		a_strConfiguration
						,		EBuildMode		a_enuMode			)			;			// @CMEMBER	Executes the specified configuration

	//																							
	//-----------------------------------------------------------------------					
	//***************************     HELPERS     ***************************					
	//-----------------------------------------------------------------------					
	//																							
private:																					// @ACCESS	Private Helper Methods	
	void AddProject		( const CString&		a_strProjectName
						, const CString&		a_strProjectPath
						, const CString&		a_strWorkspaceName
						, const CString&		a_strWorkspacePath
						, const CString&		a_strConfigurations
						,		int				a_iStyle			)			;			// @CMEMBER	Adds the specified project to the array of known projects
	void AddProject		( const CProject&		a_Project
						,		INT				a_iConfiguration	)			;			// @CMEMBER	Adds the specified project to the status display
	void UpdateProject	( const CString&		a_strStatus
						,		INT				a_iIndex	=  0
						,		INT				a_iErrors	= -1
						,		INT				a_iWarnings = -1
						,		BOOL			a_bFinished = FALSE )			;			// @CMEMBER Updates the specified project's status display

	void Reset			( void )												;			// @CMEMBER Resets the dialog

	void SendMail		( const CString&		a_strConfiguration	)			;			// @CMEMBER	Sends an e-mail
	void SendMail		( const CProject&		a_Project
						,		long			a_lErrors
						,		long			a_lWarnings			)			;			// @CMEMBER	Sends an e-mail

	BOOL LoadWorkspace	( const CString&		a_strWorkspacePath	)			;			// @CMEMBER	Loads tthe specified workspace
	void ProcessMessages(		BOOL			a_bApp		= FALSE )			;			// @CMEMBER	Processes pending messages
	void WaitForPending	( void )												;			// @CMEMBER Waits for pending project to finish building

	//																							
	//-----------------------------------------------------------------------					
	//**************************     VIRTUALS     ***************************
	//-----------------------------------------------------------------------					
	//																							
	//{{AFX_VIRTUAL(CDialogProgress)
protected:																					// @ACCESS	Protected Overridables
	virtual void DoDataExchange			( CDataExchange* pDX );								// @CMEMBER	DDX/DDV Support
	//}}AFX_VIRTUAL

	//																							
	//-----------------------------------------------------------------------					
	//**************************     MESSAGES     ***************************
	//-----------------------------------------------------------------------					
	//																							
protected:																					// @ACCESS	Protected Message Handlers
	//{{AFX_MSG(CDialogProgress)
	virtual BOOL	OnInitDialog		();													// @CMEMBER Called to initialize the dialog
	virtual void	OnCancel			();													// @CMEMBER Called when the Cancel button is pressed
	afx_msg void	OnPause				();													// @CMEMBER Called when the Pause/Resume button is pressed
	afx_msg void	 OnSize				(UINT nType, int cx, int cy);
	afx_msg void	OnGetMinMaxInfo		(MINMAXINFO FAR* lpMMI);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public:																						// @ACCESS	Public Message Handlers
			void	OnBuildFinished		( long a_lErrors, long a_lWarnings )	;			// @CMEMBER	Called when a build has finished

	//																						
	//-----------------------------------------------------------------------				
	//***********************     CON/DESTRUCTION     ***********************				
	//-----------------------------------------------------------------------				
	//																						
public:																						// @ACCESS	Public Con-/Destruction Methods	
	CDialogProgress( CWnd* pParent = NULL );												// @CMEMBER	Default constructor
};

//{{AFX_INSERT_LOCATION}}

#endif // #ifndef			__DIALOGPROGRESS_H_INCLUDED
